// ----------------------------------------
// Filename: Ready_Queue.h
// Description: The header file for a ready queue
// Author: Jon Maloney
// Date: 30-May-2012
//

#ifndef READY_QUEUE_H
#define READY_QUEUE_H

//************************************************************
//                    Include .h files
//************************************************************
#include "Linked_List.h"
#include "microRTOS.h"

//************************************************************
//                    Include external references
//************************************************************

//************************************************************
//                    Define Statements
//************************************************************

typedef enum
{
	eQueueErrorNone = 0,
	eQueueErrorInsufficientMemory,
	eQueueErrorAddFailure,
	eQueueErrorPriorityChange, 
	eQueueErrorQueueEmpty,
}QUEUE_ERROR_TYPE;
//************************************************************
//                    Struct, Union, enum Statements
//************************************************************

typedef struct 
{
	/*< An array of pointers to linked lists >*/
	linkedList_Handle rQueues[ configNB_PRIORITY_LEVELS ];
	/*< An indication of the highest priority task in the queue.*/
	UINT8 higestPriorityElementInQueue;					
}T_READY_QUEUE;


typedef T_READY_QUEUE * rQueue_Handle;
//************************************************************
//                    Global variables and constants
//************************************************************

//************************************************************
//                    Prototype Global Functions
//************************************************************
rQueue_Handle ReadyQueue_Create( void );

QUEUE_ERROR_TYPE ReadyQueue_Add( T_READY_QUEUE * rQueue, linkedList_Handle node, void * item, PRIORITY priority );

// ----------------------------------------
// ReadyQueue_AddNode
// 
// Adds node to the ready queue.
//	
// Input:
// 	rQueue: 	The ready queue that the node is to be inserted into.
//	node:		The node to be inserted.
//	priority:	The priority of the element being inserted into the ready queue
// Output:
//  pdTRUE: 	If there has been a change in the queue's priority (A higher priority element has been added to the queue)
//	pdFALSE:	If no change has occured in the queue's priority. 
// Conditions:
// 	none
//
BOOL ReadyQueue_AddNode( rQueue_Handle rQueue, linkedList_Handle node, PRIORITY priority );

inline BOOL ReadyQueue_Remove( T_READY_QUEUE * rQueue, linkedList_Handle node, PRIORITY priority );

inline void ReadyQueue_Move( T_READY_QUEUE * rQueue, linkedList_Handle node, UINT8 FromPriority,  UINT8 ToPriority );

void * ReadyQueue_GetHighestPriorityItem( T_READY_QUEUE * rQueue );

void * ReadyQueue_GetAndRemoveHighestPriorityItem( T_READY_QUEUE * rQueue );

linkedList_Handle ReadyQueue_GetHighestPriorityNode( rQueue_Handle rQueue );

linkedList_Handle ReadyQueue_GetAndRemoveHighestPriorityNode( rQueue_Handle rQueue );

#endif
